package com.szholly.pro.watergas_server.ps.android.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.ps.android.common.NonNullUtil;
import com.szholly.pro.watergas_server.ps.android.common.ValidUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

/**
 * 工业废水 - 周巡检
 * 
 * 2017/6/2 <br/>
 *
 * @author Joey Huang QQ:273179370）
 */
public class IndustryWaterTaskWeekCheck extends IndustryWaterTask {

	@Override
	public Map<String, Object> getOperationTaskInitData(String userId, String pointCode, String taskCode) throws Exception {
		List<RowBase> checkItemList = queryCheckItemList();
		List<RowBase> limitList = queryLimitList(pointCode);
		List<RowBase> instrumentList = queryInstrumentList(pointCode);
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("checkItemList", checkItemList);
		resultMap.put("limitList", limitList);
		resultMap.put("instrumentList", instrumentList);
		return resultMap;
	}

	@Override
	public Map<String, Object> getOperationTaskDetailData(String userId, String pointCode, String taskCode) throws Exception {
		Map<String, Object> taskInitData = getOperationTaskInitData(userId, pointCode, taskCode);	
		return taskInitData;
	}

	@Override
	public String saveOperationTask(String taskCode, String data) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String updateOperationTask(String taskCode, String data) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	//周巡检项目
	private List<RowBase> queryCheckItemList() throws Exception {
		String sql = "select t.s_domaincode \"id\",\n"
				+ "       t.s_domaincaption \"name\",\n"
				+ "       to_char(t.i_Order) \"index\",\n"
				+ "       t.s_ischild \"isChild\"\n"
				+ "  from data_defulatdomain t\n"
				+ " where t.S_DOMAINNAME = '工业废水运维项'\n"
				+ "   and t.s_domaincode like 'A10%'\n"
				+ " order by t.s_domaincode";
		return NonNullUtil.toList(DataUtil.getSelectRows(sql, null));
	}

	// 获取仪器信息
	private List<RowBase> queryInstrumentList(String pointCode) throws Exception {
		ValidUtils.hasText(pointCode, "站点编号为空，仪器信息获取失败");
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("pointCode", pointCode));
		String sql = "select t.name \"id\",\n"
				+ "       t1.s_domaincaption || '分析仪' \"name\",\n"
				+ "       t.abnormal_max \"limitUp\",\n"
				+ "       '2017-06-02' \"validDate\"\n"
				+ "  from BC_SITE_POLL t\n"
				+ "  left join data_defulatdomain t1\n"
				+ "    on t1.s_domaincode = t.name\n"
				+ " where t1.s_domainname = 'MONITOR_PARAM'\n"
				+ "   and t.site_id = @pointCode";
		return NonNullUtil.toList(DataUtil.getSelectRows(sql, parms));
	}
	
	//获取参数排放限值
	private List<RowBase> queryLimitList(String pointCode) {
		ValidUtils.hasText(pointCode, "站点编号为空，仪器信息获取失败");
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		parms.add(new GlobalParameter("pointCode", pointCode));
		String sql = "select t.name \"id\",\n"
				+ "       t1.s_domaincaption \"name\",\n"
				+ "       t.abnormal_max \"limitUp\"\n"
				+ "  from BC_SITE_POLL t\n"
				+ "  left join data_defulatdomain t1\n"
				+ "    on t1.s_domaincode = t.name\n"
				+ " where t1.s_domainname = 'MONITOR_PARAM'\n"
				+ "   and t.site_id = @pointCode";
		return NonNullUtil.toList(DataUtil.getSelectRows(sql, parms));
	}

}
